double myPow(double x, int n){
    if (x == 0.0 || x == 1.0) return x;
    double res = 1;
    long long power = n; 
    if (power < 0) {
        power *= -1;
        x = 1/x;
    }

    while (power) {
        // x^9 = x^(1001)b = x^(1*2^0) * x^(0*2^1) * x^(0*2^2) * x^(1*2^3)
        if (power&1) { 
            res *= x;
        }   
        x = x*x;
        power >>= 1;
    }
    return res;
}